home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / xlib.zip / XCOLLECT.INT < prev    next >
Text File  |  1992-09-06  |  6KB  |  150 lines

  1. (*****************************************************************************)
  2. (*                                                                           *)
  3. (*        Filename        : XCOLLECT.PAS                                     *)
  4. (*        Autor           : Stefan Boether / Compuserve Id : 100023,275      *)
  5. (*                                                 FidoNet :  2:242/200      *)
  6. (*                                                 FidoNet :  2:243/91       *)
  7. (*                                  Internet: 100023.275@CompuServe.COM      *)
  8. (*        System          : TURBO 6.01 / MS-DOS / TPW 1.5 / WIN 3.1          *)
  9. (*        Aenderung       :                                                  *)
  10. (*        wann     was                                                wer    *)
  11. (*---------------------------------------------------------------------------*)
  12. (*        26.04.92 Added OverFlowCollection                           Stefc  *)
  13. (*        05.08.92 Added TStrCollection                               Stefc  *)
  14. (*        16.08.92 New "LookAHead" method for FiFo/LiFo Stacks        Stefc  *)
  15. (*        18.08.92 Rename unitname to XCOLLECT                        Stefc  *)
  16. (*        29.08.92 Add the "TSingleCollection" to it                  Stefc  *)
  17. (*        30.08.92 Get Ready for TPW                                  Stefc  *) 
  18. (*****************************************************************************)
  19. (*        Beschreibung:  Implements some Collections Types for TV-OWL        *)
  20. (*****************************************************************************)
  21. {Header-End}
  22.  
  23. UNIT XCollect;
  24. {$IfnDef Windows } {$O+} {$Endif}
  25.                    {$D-}
  26.  
  27. INTERFACE
  28.  
  29.   USES  {$IFDEF Windows}
  30.          (* Z:OWL\ *)       WObjects;
  31.         {$ELSE}
  32.          (* Y:TVISION\ *)   Objects;    (* Base-Objects and Collections  *)
  33.         {$ENDIF}
  34.  
  35.   TYPE   { A Stack for First-In / First-Out access }
  36.  
  37.          PFiFoCollection = ^TFiFoCollection;
  38.          TFiFoCollection = object( TCollection )
  39.            procedure Push( P : Pointer ); virtual;
  40.            function  Pop : Pointer;       virtual;
  41.            function  LookAHead:Pointer;   virtual;
  42.          end;
  43.  
  44.          { A Stack for Last-In / First-Out access }
  45.  
  46.          PLiFoCollection = ^TLiFoCollection;
  47.          TLiFoCollection = object( TFiFoCollection )
  48.            function Pop : Pointer; virtual;
  49.            function LookAHead:Pointer; virtual;
  50.          end;
  51.  
  52.          { Used in TIntegerCollections }
  53.  
  54.          PIntegerItem = ^TIntegerItem;
  55.          TIntegerItem = object ( TObject )
  56.            Item : Integer;
  57.            constructor Init( AItem: Integer );
  58.          end;
  59.  
  60.          { A sorted Collection for TIntegerItem objects }
  61.  
  62.          PIntegerCollection = ^TIntegerCollection;
  63.          TIntegerCollection = object ( TSortedCollection )
  64.            function Compare(Key1, Key2: Pointer): Integer; virtual;
  65.            function KeyOf(Item: Pointer): Pointer; virtual;
  66.          end;
  67.  
  68.          { This collection you can use for buffers where after
  69.            a number of items the oldest would be delete automatically }
  70.  
  71.          POverflowCollection = ^TOverFlowCollection;
  72.          TOverflowCollection = object ( TCollection )
  73.            MaxItems : Integer;
  74.            constructor Init( ALimit,ADelta,AMax: Integer );
  75.            procedure Insert( Item:Pointer ); virtual;
  76.          end;
  77.  
  78.          { The TStrCollection handle PString items in the same manner than
  79.            PStringCollection, but unsorted ! }
  80.  
  81.          PStrCollection = ^TStrCollection;
  82.          TStrCollection = object( TCollection )
  83.            procedure FreeItem(Item: Pointer); virtual;
  84.            function  GetItem(var S: TStream): Pointer; virtual;
  85.            procedure PutItem(var S: TStream; Item: Pointer); virtual;
  86.            procedure Writeln;
  87.          end;
  88.  
  89.          { The TPtrCollection can be used internal to collect
  90.            other Objects in memory like Windows }
  91.          PPtrCollection = ^TPtrCollection;
  92.          TPtrCollection = object( TCollection )
  93.            procedure FreeItem(Item: Pointer); virtual;
  94.            function  GetItem(var S: TStream): Pointer; virtual;
  95.            procedure PutItem(var S: TStream; Item: Pointer); virtual;
  96.          end;
  97.  
  98.          { This is a special Collection that can be used instead
  99.            of single linked lists ! }
  100.          PSingleCollection = ^TSingleCollection;
  101.          TSingleCollection = object( TObject )
  102.            Normal : Boolean;
  103.            Next   : PSingleCollection;
  104.            constructor Init( ANext:PSingleCollection );
  105.            destructor  Done; virtual;
  106.            constructor Load(var S:TStream);
  107.            procedure   Store(var S:TStream);
  108.            function    Count:Word;
  109.            procedure   ForEach(Action:Pointer);
  110.            procedure   CopyTo( ACollection:PCollection );
  111.          end;
  112.  
  113.   CONST  RFiFoCollection : TStreamRec =
  114.            ( ObjType: 20020;
  115.              VmtLink: Ofs(TypeOf(TFifoCollection)^);
  116.              Load:    @TFifoCollection.Load;
  117.              Store:   @TFifoCollection.Store
  118.            );
  119.  
  120.          RLiFoCollection : TStreamRec =
  121.            ( ObjType: 20021;
  122.              VmtLink: Ofs(TypeOf(TLiFoCollection)^);
  123.              Load:    @TLiFoCollection.Load;
  124.              Store:   @TLiFoCollection.Store
  125.            );
  126.  
  127.          ROverflowCollection : TStreamRec =
  128.            ( ObjType: 20022;
  129.              VmtLink: Ofs(TypeOf(TOverflowCollection)^);
  130.              Load:    @TOverflowCollection.Load;
  131.              Store:   @TOverflowCollection.Store
  132.            );
  133.  
  134.          RStrCollection : TStreamRec =
  135.            ( ObjType: 20023;
  136.              VmtLink: Ofs(TypeOf(TStrCollection)^);
  137.              Load:    @TStrCollection.Load;
  138.              Store:   @TStrCollection.Store
  139.            );
  140.  
  141.          RSingleCollection: TStreamRec =
  142.            ( ObjType: 20024;
  143.              VmtLink: Ofs(TypeOf(TSingleCollection)^);
  144.              Load:    @TSingleCollection.Load;
  145.              Store:   @TSingleCollection.Store
  146.            );
  147.  
  148.   PROCEDURE RegisterXCollect;
  149.  
  150.